import 'package:easy_refresh/easy_refresh.dart';
import 'package:enterprise_v8/app/core/core.dart';

import 'home_page_control.dart';

/// 首页  (需要测试页面,不做正式用)
class HomePagePage extends StatelessWidget {
  HomePagePage({super.key});

  final control = Get.put(HomePageControl());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: AppColors.bg_color_grey,
        body: EasyRefresh(
          header: const MaterialHeader(),
          onRefresh: () async {
            await Future.delayed(const Duration(seconds: 1), () {
              // control.refresh();
            });
          },
          child: CustomScrollView(
            slivers: [
              SliverAppBar(
                title: const Text('四川寰宇纵横科技'),
                actions: [
                  IconButton(
                    tooltip: '全局菜单检索',
                    icon: const Icon(Icons.search),
                    onPressed: () {
                      // 跳转到搜索页面
                      // Get.toNamed(AppRoutes.homeSearch);
                    },
                  ),
                ],
              ),
              // 轮播
              SliverToBoxAdapter(
                child: Container(
                  margin: const EdgeInsets.all(16),
                  height: 160,
                  decoration: BoxDecoration(
                    color: Colors.green[100],
                    borderRadius: BorderRadius.circular(12),
                  ),
                  alignment: Alignment.center,
                  child: const Text('企业重要信息轮播,没有数据就不显示这块'),
                ),
              ),
              SliverPadding(
                padding: const EdgeInsets.all(16),
                sliver: SliverGrid(
                  gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                    crossAxisCount: 5,
                    crossAxisSpacing: 10,
                    mainAxisSpacing: 10,
                    childAspectRatio: 1,
                  ),
                  delegate: SliverChildBuilderDelegate(
                    (BuildContext context, int index) {
                      return Container(
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                            color: Colors.blue[100 * ((index % 8) + 1)],
                            borderRadius: BorderRadius.circular(12),
                          ),
                          child: Text('模块 $index'),
                      );
                    },
                    childCount: 8,
                  ),
                ),
              ),

              SliverToBoxAdapter(
                child: Container(
                  margin: const EdgeInsets.all(16),
                  height: 160,
                  decoration: BoxDecoration(
                    color: Colors.green[100],
                    borderRadius: BorderRadius.circular(12),
                  ),
                  alignment: Alignment.center,
                  child: const Text('重要的数据图表(报警信息(日/周/月))'),
                ),
              ),

              SliverToBoxAdapter(
                child: Container(
                  margin: const EdgeInsets.all(16),
                  height: 160,
                  decoration: BoxDecoration(
                    color: Colors.green[100],
                    borderRadius: BorderRadius.circular(12),
                  ),
                  alignment: Alignment.center,
                  child: const Text('重要的数据图表(人车分布统计)'),
                ),
              ),

              SliverToBoxAdapter(
                child: Container(
                  margin: const EdgeInsets.all(16),
                  height: 160,
                  decoration: BoxDecoration(
                    color: Colors.green[100],
                    borderRadius: BorderRadius.circular(12),
                  ),
                  alignment: Alignment.center,
                  child: const Text('数据图表展示(人流,车流统计)'),
                ),
              ),

              SliverToBoxAdapter(
                child: Container(
                  margin: const EdgeInsets.all(16),
                  height: 160,
                  decoration: BoxDecoration(
                    color: Colors.green[100],
                    borderRadius: BorderRadius.circular(12),
                  ),
                  alignment: Alignment.center,
                  child: const Text('安全风险实时统计柱状图'),
                ),
              ),

              SliverToBoxAdapter(
                child: Container(
                  margin: const EdgeInsets.all(16),
                  height: 160,
                  decoration: BoxDecoration(
                    color: Colors.green[100],
                    borderRadius: BorderRadius.circular(12),
                  ),
                  alignment: Alignment.center,
                  child: const Text('实时监控模块'),
                ),
              ),

            ],
          ),
        ));
  }
}
